package ar.edu.caece.compiler.error;

import ar.edu.caece.compiler.grammar.Recognizer;
import ar.edu.caece.compiler.grammar.TokenRecognizer;

public class ParsingException extends Exception{

  private static final long serialVersionUID = 1L;

  private Class<? extends Recognizer> expected;
  private TokenRecognizer received;
  
  public ParsingException(String message, Class<? extends Recognizer> expected, TokenRecognizer received) {
    super(message);
    this.expected = expected;
    this.received = received;
  }

  public Class<? extends Recognizer> getExpected() {
    return expected;
  }
  
  public TokenRecognizer getReceived() {
    return received;
  }
  
  @Override
  public String toString() {
    String str = "Error de parseo.";
    
    if(received != null) {
    	str += " Se recibió '" + received.getRepresentation() + "'.";
    }
    
    if(expected != null) {
    	str += " Se esperaba '" + expected.getSimpleName() + "'.";
    }
    
    return str;
  }
}
